//
//  WordCardDetailViewController.m
//  Learn
//
//  Created by 迟建国 on 2024/4/1.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "WordCardDetailViewController.h"
#import "WordCaseTableViewCell.h"

@interface WordCardDetailViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation WordCardDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"开始背单词";
    self.view.backgroundColor = UIColor.whiteColor;
    [self setUI];
    // Do any additional setup after loading the view.
}

- (void)setUI {
    
    UIButton *readBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [readBtn setImage:[UIImage imageNamed:@"icon_read"] forState:UIControlStateNormal];
    [self.view addSubview:readBtn];
    [readBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(self.view.mas_top).offset(NavigationBarHeight);
        make.width.height.offset(40);
    }];
    
    UILabel *workL = [[UILabel alloc] init];
    workL.text = @"worksss";
    workL.textAlignment = NSTextAlignmentCenter;
    workL.textColor = rgba(51, 51, 51, 1);
    workL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:32];
    [self.view addSubview:workL];
    [workL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(15);
        make.top.equalTo(self.view.mas_top).offset(NavigationBarHeight + 40);
        make.right.equalTo(self.view.mas_right).offset(-15);

    }];
    
    UILabel *pinyinL = [[UILabel alloc] init];
    pinyinL.text = @"[a'bAv]";
    pinyinL.textColor = rgba(142, 142, 142, 1);
    pinyinL.textAlignment = NSTextAlignmentCenter;
    pinyinL.font = [UIFont fontWithName:@"PingFangSC-Regular" size:18];
    [self.view addSubview:pinyinL];
    [pinyinL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(15);
        make.top.equalTo(workL.mas_bottom).offset(10);
        make.right.equalTo(self.view.mas_right).offset(-15);
    }];
    
    UILabel *meanL = [[UILabel alloc] init];
    meanL.text = @"剋爱的，美丽的动人的";
    meanL.textColor = rgba(142, 142, 142, 1);
    meanL.textAlignment = NSTextAlignmentCenter;
    meanL.font = [UIFont fontWithName:@"PingFangSC-Regular" size:18];
    [self.view addSubview:meanL];
    [meanL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(15);
        make.top.equalTo(pinyinL.mas_bottom).offset(15);
        make.right.equalTo(self.view.mas_right).offset(-15);
    }];
    
    UIImageView *cardImageView = [[UIImageView alloc] init];
    cardImageView.image = [UIImage imageNamed:@""];
    cardImageView.layer.cornerRadius = 10;
    cardImageView.layer.masksToBounds = YES;
    cardImageView.backgroundColor = UIColor.redColor;
    [self.view addSubview:cardImageView];
    [cardImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(meanL.mas_bottom).offset(30);
        make.left.equalTo(self.view.mas_left).offset(27);
        make.right.equalTo(self.view.mas_right).offset(-27);
        make.height.offset(180);
    }];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = rgba(12, 183, 108, 1);
    [self.view addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(27);
        make.top.equalTo(cardImageView.mas_bottom).offset(19);
        make.width.offset(4);
        make.height.offset(14);
    }];
    
    UILabel *caseL = [[UILabel alloc] init];
    caseL.text = @"例句";
    caseL.textColor = rgba(142, 142, 142, 1);
    caseL.textAlignment = NSTextAlignmentCenter;
    caseL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:16];
    [self.view addSubview:caseL];
    [caseL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lineView.mas_right).offset(5);
        make.centerY.equalTo(lineView.mas_centerY);
    }];
    
    self.tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 407 + NavigationBarHeight, SCREEN_W, 200) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.tableView.backgroundColor=[UIColor clearColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    [self.tableView registerNib:[UINib nibWithNibName:@"WordCaseTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"WordCaseTableViewCell"];
    
    UIButton *continueBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [continueBtn setTitle:@"继续做题" forState:UIControlStateNormal];
    [continueBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    continueBtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:18];
    continueBtn.backgroundColor = rgba(41, 241, 156, 1);
    continueBtn.layer.cornerRadius = 22.5;
    continueBtn.layer.masksToBounds = YES;
//    [continueBtn addTarget:self action:@selector(sure) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:continueBtn];
    [continueBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(-10);
        make.left.equalTo(self.view.mas_left).offset(10);
        make.bottom.equalTo(self.view.mas_bottom).offset(-SafeAreaBottomHeight - 10);
        make.height.offset(45);
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    WordCaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WordCaseTableViewCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"WordCaseTableViewCell" owner:self options:nil] lastObject];
    }
    return cell;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

@end
